// https://github.com/umijs/umi/tree/master/packages/umi-plugin-locale
import {formatMessage, setLocale, getLocale, FormattedMessage} from 'umi-plugin-locale';
import {Button} from "antd";

// 渲染一个文字标签
export default () => {
  // 获取指定文字的多语言版本
  const formatedText = formatMessage(
    {id: 'WELCOME_TO_UMI_WORLD'},
    {name: '小伙子',}
  );

  function changLang() {
    const locale = getLocale();
    if (!locale || locale === 'zh-CN') {
      setLocale('en-US');
    } else {
      setLocale('zh-CN');
    }
  }

  return (
    <div>
      {/*使用组件获取语言*/}
      <FormattedMessage id="WELCOME_TO_UMI_WORLD" values={{name: '小伙子'}}/>
      <div>{formatedText}</div>
      <Button
        size="small"
        onClick={() => {
          changLang();
        }}
      >
        <FormattedMessage id="lang" />
      </Button>
    </div>
  );
}
